from rest_framework_mongoengine.serializers import DocumentSerializer, serializers

from models.task import ScanTaskSessionsExtra


class LastTaskData(object):
    def __init__(self, task_id, task_type_tuple: tuple, limit):
        self.task_id = task_id
        self.limit = limit
        self.func_dict = {
            task_type: f"get_{task_type}" for task_type in task_type_tuple
        }

    def get(self):
        data = {}
        for task_type, func in self.func_dict.items():
            data[task_type] = func()

        return data

    def get_availability(self):
        pass

    def get_securityEvent(self):
        pass

    def get_vul(self):
        pipeline = [{'$match': {'task_id': self.task_id}}]  # noqa: F841

    def get_risk_link(self):
        pass

    def get_target_info(self):
        pass

    def _get_event_info(self):
        pass


class TaskSessionExtraSerializer(DocumentSerializer):
    class Meta:
        model = ScanTaskSessionsExtra
        fields = [
            'task_session_id',
            'user_id',
            'target_id',
            'data_version',
            'system_version',
            'status',
            'status_name',
            'reason',
        ]

    task_session_id = serializers.CharField()
    user_id = serializers.CharField()
    target_id = serializers.CharField()
    data_version = serializers.CharField()
    system_version = serializers.CharField()
    status = serializers.IntegerField(required=False)
    status_name = serializers.CharField(required=False)
    reason = serializers.CharField(required=False)
